package zozopo.warehouse;

import java.util.List;
import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import zozopo.background.operator.operations.OperatorTB;
import zozopo.background.operator.operations.OperatorlimitedTB;
import zozopo.user.operations.UserOS;
import zozopo.user.operations.UserTB;
import zozopo.warehouse.operations.AftersaleserviceOS;
import zozopo.warehouse.operations.AftersaleserviceTB;
import zozopo.warehouse.operations.ReceiptOS;
import zozopo.warehouse.operations.ReceiptTB;
import zozopo.warehouse.operations.ReceiptlistOS;
import zozopo.warehouse.operations.ReceiptlistTB;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;

public class PreAddBackreceiptlistAction extends ActionSupport implements Action,SessionAware{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private static final String limitedCode ="WAREHOUSE.BACKRECEIPTLIST.ADD";
	
	//传入参数
	private int receiptlistid;

	
	//传出参数
	private ReceiptlistTB receiptlist;
	private List<ReceiptTB> receiptList;
	private List<AftersaleserviceTB> aftersaleserviceList;
	
	private Map<Object, Object> session;
	
	public void setSession(Map arg0) {
		// TODO Auto-generated method stub
		session = arg0;
	}
	
	
	public String execute(){
			
			//权限处理
		
			
			String forward = SUCCESS;
			
			
			
			ReceiptlistOS receiptlistOS = new ReceiptlistOS();
			ReceiptOS receiptOS = new ReceiptOS(receiptlistOS.getConn());
			AftersaleserviceOS aftersaleserviceOS = new AftersaleserviceOS(receiptlistOS.getConn());
			try{
				receiptlist = receiptlistOS.getReceiptlistById(receiptlistid);
				receiptList = receiptOS.getListByReceiptlistId(receiptlistid);
				aftersaleserviceList = aftersaleserviceOS.selectByReceiptlistid(receiptlistid);
				
			}catch (Exception e) 
			{
				forward = ERROR;
				e.printStackTrace();
				
			}finally{
				receiptlistOS.releaseConnection();
			}
			
			return forward;
	}

	public void validate() {
		//权限处理
		OperatorTB operator = (OperatorTB)session.get("operatorInfo"); 
	
		if(operator == null){
			addFieldError("errormessage",getText("operator.timeoutornotlogin"));
			return ; 
		} 
		
		//用户权限
		Map<String,OperatorlimitedTB> operatorlimitedMap = (Map<String,OperatorlimitedTB>)session.get("operatorlimitedMap");
		
		if(operatorlimitedMap.get(limitedCode) == null){
			addFieldError("errormessage","用户未有退货权限.");
			return;
		}
	}



	public ReceiptlistTB getReceiptlist() {
		return receiptlist;
	}


	public void setReceiptlist(ReceiptlistTB receiptlist) {
		this.receiptlist = receiptlist;
	}


	public List<ReceiptTB> getReceiptList() {
		return receiptList;
	}


	public void setReceiptList(List<ReceiptTB> receiptList) {
		this.receiptList = receiptList;
	}


	public List<AftersaleserviceTB> getAftersaleserviceList() {
		return aftersaleserviceList;
	}


	public void setAftersaleserviceList(
			List<AftersaleserviceTB> aftersaleserviceList) {
		this.aftersaleserviceList = aftersaleserviceList;
	}


	public int getReceiptlistid() {
		return receiptlistid;
	}


	public void setReceiptlistid(int receiptlistid) {
		this.receiptlistid = receiptlistid;
	}


	public static String getLimitedcode() {
		return limitedCode;
	}

}
